<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="所属用户:" prop="user_id.value">
                            <SelectPage v-model="queryParams.user_id.value" placeholder="请选择所属用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="投诉分类:" prop="category1.value">
                            <SelectCategory url="/admin/sq.category/tree" ref="category" :queryParams="{type: 3 }"
                                            :check-strictly="true"
                                            :value="[queryParams.category1.value]"
                                            @change="onChangeCategory"></SelectCategory>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="状态:" prop="status.value">
                            <el-select v-model="queryParams.status.value">
                                <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5" v-if="false">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5" v-if="false">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="80">
                        <template slot-scope="scope">
                            <el-button size="mini" v-if="scope.row.status === 1"
                                       type="text" icon="el-icon-edit" @click="handleEdit(scope.row)"
                                       v-hasPermi="api.edit">编辑</el-button>
                            <el-button size="mini" type="text" v-else
                                       icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" v-if="false"
                                       @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
        <el-dialog title="动态/科普详情" :visible="postVisible" append-to-body :before-close="()=>{ postVisible=false }" destroy-on-close>
            <post1Info ref="editForm1" :findFormData="currentRow.postInfo" :disabled="true" :edit-form-params="{}" @editFormCancel="postVisible=false" v-if="currentRow.postInfo.data_type === 1" />
            <post2Info ref="editForm2" :findFormData="currentRow.postInfo" :disabled="true" :edit-form-params="{}" @editFormCancel="postVisible=false" v-if="currentRow.postInfo.data_type === 2" />
            <post3Info ref="editForm3" :findFormData="currentRow.postInfo" :disabled="true" :edit-form-params="{}" @editFormCancel="postVisible=false" v-if="currentRow.postInfo.data_type === 3" />
        </el-dialog>
    </div>
</template>
<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
import SelectCategory from "../../../components/My/SelectCategory";
import post1Info from '../post/EditFormCom.vue'
import post2Info from '../post2/EditFormCom.vue'
import post3Info from '../post3/EditFormCom.vue'

export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: {SelectCategory, EditForm, post1Info, post2Info, post3Info },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '所属用户',
                    prop: 'myUser.nickname',
                },
                {
                    visible: true,
                    label: '动态/科普',
                    prop: 'post_id',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.post_id}</a>`
                    },
                    click: (prop, row)=> {
                        this.currentRow = row
                        this.postVisible = true
                    }
                },
                {
                    visible: true,
                    label: '分类',
                    prop: 'category1_text',
                },
                {
                    visible: true,
                    label: '描述',
                    prop: 'content',
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status_text'
                },
                {
                    visible: true,
                    label: '结果类型',
                    prop: 'handle_type_text'
                },
                {
                    visible: true,
                    label: '创建时间',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                }
            ],
            // 接口地址
            api: {
                index: `/admin/sq.post_report/index`,
                find: `/admin/sq.post_report/find`,
                add: `/admin/sq.post_report/add`,
                edit: `/admin/sq.post_report/edit`,
                delete: `/admin/sq.post_report/delete`,
                export: `/admin/sq.post_report/export`,
                status: `/admin/sq.post_report/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                user_id: { value:undefined, op: '='},
                category1: { value:undefined, op: '='},
                status: { value:undefined, op: '='},
            },
            status: [
                { value: undefined, label: '全部'},
                { value: 1, label: '未处理' },
                { value: 2, label: '已处理' }
            ],
            currentRow: {
                postInfo: {}
            },
            postVisible: false
        }
    },
    methods: {
        onChangeCategory(e, pathLabels) {
            e = e || []
            pathLabels = pathLabels || []
            this.$set(this.queryParams.category1, 'value', e.length >= 1 ? e[0] : '')
        },
    }
}
</script>
